/*
 * Copyright (C) 2025 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the 'License');
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an 'AS IS' BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
export type unionType = string | number | boolean;

export function fUnionType(value: unionType): unionType {
  if (typeof value === 'string') {
    return value.toUpperCase();
  } else if (typeof value === 'number') {
    return value * 2;
  } else {
    return !value;
  }
}


type T1 = [string, number, boolean];

function f1(tuple: T1): T1 {
  return [
    tuple[0].toUpperCase(),
    tuple[1] * 2,
    !tuple[2]
  ];
}


const testTuple: T1 = ["hello", 42, true];
export const result: T1 = f1(testTuple);



type K = { name: string, age: number };
type alias = K;
function f2(person: alias): string {
  return `Name: ${person.name}, Age: ${person.age}`;
}
const person: alias = { name: "Alice", age: 30 };
export const result1: string = f2(person);


type T2 = { name: string, age: number };
function f3(person: T2): string {
  return `Name: ${person.name}, Age: ${person.age}`;
}
const person1: T2 = { name: "Bob", age: 25 };
export const result2: string = f3(person1);
console.log(result2);



interface X {
  (arg: number): number;
}
const func: X = (arg: number): number => arg * 2;
export const result3: number = func(42);



interface indexX {
  [index: string]: number;
}
export const myObject: indexX = {
  a: 1,
  b: 2,
  c: 3
};


interface intersectingT1 {
  name: string;
}
interface intersectingT2 {
  age: number;
}

export const intersectingMyObject: intersectingT1 & intersectingT2 = {
  name: "Alice",
  age: 30
};
const someArray = [10, 20, 30];

export const element = someArray[1];



interface GenericsT {
  name: string;
  age: number;
}
type A<GenericsT> = { [K in keyof GenericsT]: GenericsT[K] };
export const GenericsMyObject: A<GenericsT> = {
  name: "Alice",
  age: 30
};

type AB = "A" | "B";
type AllLocaleIDs = `${AB}_id`;
export const myId: AllLocaleIDs = "A_id";